<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var matrixReshape = function(nums, r, c) {
        let row = nums.length;
        let col = nums[0].length;
        if(r*c!=row*col || (r==row && c==col))return nums;
        let arr = nums.reduce((pre,cur)=>{
            return pre.concat(cur);
        });
        
        let res = [];
        for(let i=0; i<r; i++){
            res.push(arr.splice(0,c));
        }
        return res;
    };  
    let nums = [[1,2],[3,4],[5,6]],r=2,c=3;
    console.log(matrixReshape(nums,r,c));
    
</script>
</html>